package com.server.user.controller;

import com.server.liad.api.file.remote.RemoteFileService;
import com.server.liad.api.system.remote.RemoteSystemService;
import com.server.common.code.utils.AjaxResult;
import com.server.common.code.utils.BeanUtils;
import com.server.common.redis.RedisService;
import com.server.common.security.code.SecurityUtils;
import com.server.common.security.code.anntation.Log;
import com.server.model.all.user.bo.ForgetPasswordBo;
import com.server.model.all.user.bo.RegisterUserBo;
import com.server.model.all.user.dto.ForgetPasswordDto;
import com.server.model.all.user.dto.RegisterUserDto;
import com.server.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户
 * @author LXC
 * @date 2022/5/5 13:17
 */
@RestController
@Slf4j
@RequestMapping(path = "/systemUser")
@Api(value = "用户",tags = "用户")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private RemoteFileService remoteFileService;

    @Resource
    private RedissonClient redissonClient;

    @Resource
    private RedisService redisService;

    @Resource
    private RemoteSystemService remoteSystemService;


    /**
     * 获取用户信息
     * @author LXC
     * @date 2022/5/2 19:13
     */
    @PostMapping("/getUserInfo")
    @ApiOperation(value = "获取用户信息")
    public AjaxResult getUserInfo(){
        return AjaxResult.successData(userService.getUserInfo(SecurityUtils.getLoginVo().getUserId()));
    }

    /**
     * 主账号注册
     * @author LXC
     * @date 2022/5/3 16:53
     */
    @Log
    @PostMapping("/api/register")
    @ApiOperation(value = "主账号注册")
    public AjaxResult register(@RequestBody @Validated RegisterUserDto registerUserDto){
        RegisterUserBo registerUserBo = BeanUtils.copyProperties(registerUserDto, RegisterUserBo.class);
        return AjaxResult.success(userService.register(registerUserBo),"注册成功");
    }

    /**
     * 忘记密码
     * @author LXC
     * @date 2022/11/13 14:11
     */
    @Log
    @PostMapping("/api/forgetPassword")
    @ApiOperation(value = "忘记密码")
    public AjaxResult forgetPassword(@RequestBody @Validated ForgetPasswordDto forgetPasswordDto){
        ForgetPasswordBo forgetPasswordBo = BeanUtils.copyProperties(forgetPasswordDto, ForgetPasswordBo.class);
        return AjaxResult.success(userService.forgetPassword(forgetPasswordBo),"修改成功");
    }

}
